import { Node } from "@tiptap/core";
import { Plugin, PluginKey } from "prosemirror-state";

export const drawKey = new PluginKey("draw");
export default Node.create({
  // 配置 ……
  name: 'paragraph',
  content: 'text*',
  group: 'block',
  renderHTML({ HTMLAttributes }) {
    return ['node-view', HTMLAttributes, 0]
  },
  addNodeView() {
    return ({
      editor,
      node,
      getPos,
      HTMLAttributes,
      decorations,
      extension,
    }) => {
      const dom = document.createElement("div");
      const plugin = editor.state.plugins.find((p) => p.key === drawKey);
      const drawPlugin = drawKey.get(editor.state);
      console.log(drawPlugin)
      console.log(drawKey)
      console.log(plugin)
      console.log(editor)
      console.log(node)
      // dom.contentEditable = true;
      // dom.innerHTML = "你好，我是一个视图节点！";
      const span = document.createElement("span");
      span.innerHTML = "你好，我是一个视图节点！";
      span.contentEditable = true;
      dom.append(span)
      return {
        dom,
        // contentDOM: span,
      };
    };
  },
});
